package com.wanmait.myhouse.mediatorController;

import com.wanmait.myhouse.dao.MediatorDAO;
import com.wanmait.myhouse.vo.Mediator;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("mediator")
public class MediatoramendController {

    @GetMapping("amend")
    public String amend(){
        return "/mediator/amend";
    }


    @PostMapping("selectByPass")
    @ResponseBody
    public String selectByPass(Mediator mediator){
        MediatorDAO mediatorDAO = new MediatorDAO();
        Mediator byId = mediatorDAO.findById(mediator.getId());
        if (byId.getMediatorPass().equals(mediator.getMediatorPass())){
            return "1";
        }else {
            return "0";
        }
    }
    @PostMapping("updateByPass")
    @ResponseBody
    public String updateByPass(Mediator mediator, HttpSession session){
        MediatorDAO mediatorDAO = new MediatorDAO();
        mediatorDAO.gaimima(mediator);
        session.invalidate();
        return "0";
    }
}
